#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QImage>
#include <QFileDialog>
#include <QDir>
#include <QDesktopServices>
#include <QDebug>
#include <QImageReader>
#include <QImageWriter>
#include <QDateTime>

#include "externaltools.h"
#include "config.h"
#include "spellchecker.h"
#include "ortho.h"
#include "filedialog.h"

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
		Q_OBJECT

	private:
		Ui::Widget *ui;

		QImage m_image1;
		QImage m_image2;
		Config* m_config;
		FileDialog* m_fileDialog;

		bool m_imageModified;

		int m_mode;

		void setMode (int mode);	// 0 = modif image, 1 = corriger le texte

		Tesseract* m_tesseract;
		QString m_text;
		SpellChecker* m_spellChecker;

		void runTesseract (QString fileName);

		static QString loadFilters ()
		{

			QList<QByteArray> formats (QImageReader::supportedImageFormats ());

			QString filter ('(');
			foreach (QByteArray ba, formats)
				filter += ba.prepend ("*.").append (' ');

			filter += ')';
			return tr ("Images %1").arg (filter);
		}

		static QString saveFilters ()
		{

			QList<QByteArray> formats (QImageWriter::supportedImageFormats ());

			QString filter ('(');
			foreach (QByteArray ba, formats)
				filter += ba.prepend ("*.").append (' ');

			filter += ')';
			return tr ("Images %1").arg (filter);
		}

		QImage convert (QImage source);

	public:
		explicit Widget(QWidget *parent = 0);
		~Widget();
		void clear ();

		void open(QString imageName);

		void setImageModified (bool b) { m_imageModified = b; }
		bool imageModified () { return m_imageModified; }

	private slots:

		void onEndOfOCR (QString resultFileName);
		void onContrastModified (int);
		void onScale1Modified(double size);
		void onScale2Modified (double size);
		void onButtonOpenClicked ();
		void onRunOCRClicked ();
		void onSpellingClicked ();
		void onCopyToClipBoardClicked ();
		void onSaveAsClicked ();
};

#endif // WIDGET_H
